<template>
<div :edit="isEdit">
<!--  {{row}}-->
  <z-form-template
      :readonly="!isEdit"
      :label-inline="true"
      :def="control.def"
      @model-change="control.onUpdate"
      @ready="onReady"
  >
  </z-form-template>
  <div v-if="isEdit">
    <el-button @click="handleAdd">添加</el-button>
  </div>
</div>
</template>

<script>
import {FormHelper} from "../../../../src/main";
const {FormInput} = FormHelper
// import Vue, {watch} from 'vue/dist/vue.esm'

export default {
  name: "MngEdit",
  props: {
    row: null,
    isEdit: {
      type: Boolean
    }
  },
  setup(props, ctx) {
    let formCtx = null;
    let control =  {
      def: {
        properties: {
          sourceTable: {
            ...FormInput('sourceTable', {

            }),
            rules: [],
          },
        }
      },
      onUpdate(e) {
        console.log('onUpdate', e)
      }
    }

    function onReady(e) {
      // console.log('e', e)
      formCtx = e.form;
      if (props.row) {
        formCtx.importData(props.row)
      }
    }

    function handleAdd() {
      ctx.emit('confirm', formCtx)
    }

    return {
      onReady,
      handleAdd,
      control
    }
  }
}
</script>

<style scoped>

</style>
